package com.sxbbc.api.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.function.common.GetRest;
import com.function.common.RestResponse;
import com.sxbbc.api.common.CustomerMapping;
import com.sxbbc.api.common.MappingUtils;
import com.sxbbc.common.basics.service.config.Config;
import com.sxbbc.common.basics.utils.calculation.CalcuUtils;
import com.sxbbc.common.basics.utils.dto.Properties;
import com.sxbbc.common.basics.utils.encrypts.pwd.Encode;
import com.sxbbc.common.basics.utils.regular.RpxUtils;
import com.sxbbc.common.basics.utils.statics.StaticUtils;
import com.sxbbc.common.core.dto.jz.UrlVo;
import com.sxbbc.common.core.entity.jz.BBusiness;
import com.sxbbc.common.core.entity.jz.CCustomer;
import com.sxbbc.common.core.entity.jz.CCustomerAuthen;
import com.sxbbc.common.core.entity.jz.Industry;
import com.sxbbc.common.core.enums.BusinessScopeEnums;
import com.sxbbc.common.core.enums.BusinessTypeEnums;
import com.sxbbc.common.core.enums.FromTypeEnums;
import com.sxbbc.common.core.service.*;
import com.sxbbc.common.core.service.system.login.LoginTokenService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 开店 控制层
 *
 * @author leehao
 * @date 2019-05-24 16:31
 */
@RestController

public class OpenShopController {

    @Autowired
    private LoginTokenService loginTokenService;
    @Autowired
    private BBusinessService businessService;
    @Autowired
    private ICCustomerAuthenService customerAuthenService;
    @Autowired
    private ICCustomerService icCustomerService;
    @Autowired
    private IIndustryService industryService;
    @Autowired
    private IAddressService iAddressService;

    /**
     * 第一次申请开店入驻
     *
     * @param token    获取迟到
     * @param business 申请资料想你想
     * @return com.function.common.RestResponse
     * @author leehao
     */
    @RequestMapping(value = CustomerMapping.APPLY_OPEN_BUSINESS)
    public RestResponse applyOpenBusiness(String token, BBusiness business) {
        //token非空时获取cid绑定到店铺
        Integer cid = loginTokenService.validLoginCid(token);
        CCustomer customer = icCustomerService.getById(cid);
        if (customer == null) {
            return GetRest.getFail("该用户不存在");
        }
        CalcuUtils calUtil = CalcuUtils.getInstance();
        RpxUtils rpxUtils = RpxUtils.getInstance();
        //关键词
        StringBuffer keyWord = new StringBuffer();
//        if (calUtil.isEquals(business.getOnOff(), BusinessScopeEnums.ONLINE.getId())) {
////            if (StringUtils.isBlank(business.getLogo())) {
////                return GetRest.getFail("请上传店铺LOGO");
////            }
//            if (StringUtils.isBlank(business.getNickNameOn())) {
//                return GetRest.getFail("请输入店铺名称");
//            }
//            keyWord.append(business.getNickNameOn()).append(BusinessScopeEnums.ONLINE.getName());
//            business.setStatus(StaticUtils.STATUS_APPLY);
//        } else
        if (calUtil.isEquals(business.getOnOff(), BusinessScopeEnums.OFFLINE.getId())) {
            if (StringUtils.isBlank(business.getHeadUrl())) {
                return GetRest.getFail("请上传店铺头像");
            }
            if (StringUtils.isBlank(business.getNickName())) {
                return GetRest.getFail("请输入店铺名称");
            }
            if (StringUtils.isBlank(business.getLinkPhone())) {
                return GetRest.getFail("请输入线下联系电话");
            }
            if (!StringUtils.equals(rpxUtils.validPhone(business.getLinkPhone()), "")) {
                return GetRest.getFail(rpxUtils.validPhone(business.getLinkPhone()));
            }
            keyWord.append(business.getNickName()).append(BusinessScopeEnums.OFFLINE.getName());
            business.setOfflineStatus(StaticUtils.STATUS_APPLY);
        } else {
            return GetRest.getFail("商家类型参数异常");
        }
        if (business.getOnOff() == null) {
            return GetRest.getFail("请选择申请类型");
        }
        if (StringUtils.isBlank(business.getWorkTime())) {
            return GetRest.getFail("请选择工作时间");
        }
        String[] split = business.getWorkTime().split("~");
        if (split.length != 2 || !business.getWorkTime().contains(":")) {
            return GetRest.getFail("营业时间格式错误,请检查是否有 ~ 和两个 : 字符");
        }
        if (business.getBType() == null) {
            return GetRest.getFail("请选择店铺类型");
        }
        if (business.getScale() == null) {
            return GetRest.getFail("请选择店铺让利比例");
        }
        if (business.getOnOff() == null) {
            return GetRest.getFail("请选择申请类型");
        }
        if (StringUtils.isBlank(business.getPhone())) {
            return GetRest.getFail("请输入联系电话");
        }
        if (!StringUtils.equals(rpxUtils.validPhone(business.getPhone()), "")) {
            return GetRest.getFail(rpxUtils.validPhone(business.getPhone()));
        }
//        if (StringUtils.isBlank(business.getCompanyName())) {
//            return GetRest.getFail("请输入企业名称");
//        }
        if (StringUtils.isBlank(business.getRealName())) {
            return GetRest.getFail("请输入法人姓名");
        }
        if (StringUtils.isBlank(business.getCardFileFront())) {
            return GetRest.getFail("请上传身份证正面");
        }
        if (StringUtils.isBlank(business.getCardFileBack())) {
            return GetRest.getFail("请上传身份证反面");
        }
        if (StringUtils.isBlank(business.getBusLicense())) {
            return GetRest.getFail("请上传营业执照");
        }
        if (StringUtils.isBlank(business.getLicenseCode())) {
            return GetRest.getFail("请输入营业执照号");
        }
        if (business.getLicenseCode().length() < 15) {
            return GetRest.getFail("请输入正确的营业执照号（15位）");
        }
        if (business.getIndustryId() == null) {
            return GetRest.getFail("请选择店铺所属行业");
        }
        if (business.getProId() == null) {
            return GetRest.getFail("请选择店铺所属地区");
        }

        //检查认证情况
        QueryWrapper<CCustomerAuthen> wrapper = new QueryWrapper<>();
        wrapper.eq("cid", cid).eq("status", StaticUtils.STATUS_SUCCESS);
        CCustomerAuthen authen = customerAuthenService.getOne(wrapper);
        if (authen == null) {
            return GetRest.getFail("该用户未认证，请认证后再申请！");
        }

        ArrayList<Integer> list = new ArrayList<>();
        list.add(StaticUtils.STATUS_APPLY);
        list.add(StaticUtils.STATUS_SUCCESS);
        QueryWrapper<BBusiness> businessQueryWrapper = new QueryWrapper<>();
        businessQueryWrapper.eq("cid", cid).in("offline_status", list);
        int count = businessService.count(businessQueryWrapper);
        if (count > 0) {
            return GetRest.getFail("您的入驻申请已提交或通过,不能再次申请。");
        }

        business.setCid(cid);
        //来源类型设置在申请入驻
        business.setFromType(FromTypeEnums.SELF_SETTLED.getId());
        //商家默认交易密码为888888
        business.setPayWord(Encode.md5Encode(StaticUtils.DEFAULT_PASSWORD));
        if (StringUtils.isNotBlank(business.getUrls())) {
            JSONArray jsonArray = new JSONArray();
            String[] urls = business.getUrls().split(",");
            for (String url : urls) {
                JSONObject obj = new JSONObject();
                obj.put("url", url);
                jsonArray.add(obj);
            }
            business.setCoverUrl(jsonArray.toString());
        }
        if (calUtil.isEquals(business.getBType(), BusinessTypeEnums.OWN_BUSINESS.getId())) {
            keyWord.append(BusinessTypeEnums.OWN_BUSINESS.getName());
        } else if (calUtil.isEquals(business.getBType(), BusinessTypeEnums.SETTLED.getId())) {
            keyWord.append(BusinessTypeEnums.SETTLED.getName());
        }

        business.setKeyWord(keyWord.toString());
        return businessService.addBusinessForApi(business);
    }

    /**
     * 申请开店后再次申请另外范围
     *
     * @param token    获取cid
     * @param business 商家对象
     * @return com.function.common.RestResponse
     * @author leehao
     */
//    @RequestMapping(value = CustomerMapping.EDIT_APPLY_BUSINESS)
//    public RestResponse handleEditBusiness(String token, BBusiness business) {
//        CalcuUtils calUtil = CalcuUtils.getInstance();
//        Integer cid = loginTokenService.validLoginCid(token);
//        CCustomer customer = icCustomerService.getById(cid);
//        if (customer == null) {
//            return GetRest.getFail("该用户不存在");
//        }
//        if (business.getId() == null) {
//            return GetRest.getFail("获取商家申请信息失败");
//        }
//        if (business.getOnOff() == null) {
//            return GetRest.getFail("请选择要申请的类型");
//        }
//        BBusiness bBusiness = businessService.getById(business.getId());
//        if (bBusiness == null) {
//            return GetRest.getFail("获取商家申请信息失败");
//        }
//        //原来的店铺范围
//        Integer originalScope = bBusiness.getOnOff();
//        if (calUtil.isEquals(bBusiness.getStatus(), StaticUtils.STATUS_FAIL)
//                || calUtil.isEquals(bBusiness.getOfflineStatus(), StaticUtils.STATUS_FAIL)) {
//            /* 情况一：被驳回，修改被驳回部分的资料 */
//            //情况1.1 第一次被驳回
//            if (calUtil.isEquals(bBusiness.getStatus(), StaticUtils.STATUS_FAIL)
//                    && calUtil.isEquals(bBusiness.getOfflineStatus(), StaticUtils.STATUS_NO)) {
//                //线上被驳回 线下未申请
//                RestResponse restResponse = checkBusinessApplyFirst(business,originalScope);
//                if (!restResponse.isStatus()) {
//                    return restResponse;
//                }
//                business.setStatus(StaticUtils.STATUS_APPLY);
//            }else if(calUtil.isEquals(bBusiness.getOfflineStatus(), StaticUtils.STATUS_FAIL)
//                    && calUtil.isEquals(bBusiness.getStatus(), StaticUtils.STATUS_NO)){
//                //线下被驳回 线上未申请
//                RestResponse restResponse = checkBusinessApplyFirst(business,originalScope);
//                if (!restResponse.isStatus()) {
//                    return restResponse;
//                }
//                business.setOfflineStatus(StaticUtils.STATUS_APPLY);
//            }
//            //情况1.2 不是第一次被驳回
//            if (calUtil.isEquals(bBusiness.getStatus(), StaticUtils.STATUS_FAIL)
//                    && calUtil.isEquals(bBusiness.getOfflineStatus(), StaticUtils.STATUS_SUCCESS)) {
//                RestResponse restResponse = checkBusinessApplySecond(business,originalScope);
//                if (!restResponse.isStatus()) {
//                    return restResponse;
//                }
//                business.setStatus(StaticUtils.STATUS_APPLY);
//                business.setOnOff(BusinessScopeEnums.ALL.getId());
//            }else if(calUtil.isEquals(bBusiness.getOfflineStatus(), StaticUtils.STATUS_FAIL)
//                    && calUtil.isEquals(bBusiness.getStatus(), StaticUtils.STATUS_SUCCESS)){
//                RestResponse restResponse = checkBusinessApplySecond(business,originalScope);
//                if (!restResponse.isStatus()) {
//                    return restResponse;
//                }
//                business.setOfflineStatus(StaticUtils.STATUS_APPLY);
//                business.setOnOff(BusinessScopeEnums.ALL.getId());
//            }
//        } else if (!calUtil.isEquals(bBusiness.getStatus(), StaticUtils.STATUS_FAIL)
//                && !calUtil.isEquals(bBusiness.getOfflineStatus(), StaticUtils.STATUS_FAIL)) {
//            /* 情况二：从没被驳回，继续申请另一范围 */
//
//            //判断是否与原来申请的类型一致
//            if (calUtil.isEquals(originalScope,business.getOnOff())) {
//                return GetRest.getFail("不可申请与原来一样的范围");
//            }
//            //判断没有被驳回且未申请
//            if (!calUtil.isEquals(bBusiness.getStatus(),StaticUtils.STATUS_FAIL)
//                    && calUtil.isEquals(bBusiness.getOfflineStatus(),StaticUtils.STATUS_NO)) {
//                //线上未驳回 线下是未申请的状态
//                RestResponse restResponse = checkBusinessApplyNoReject(business);
//                if (!restResponse.isStatus()) {
//                    return restResponse;
//                }
//                business.setOfflineStatus(StaticUtils.STATUS_APPLY);
//                business.setOnOff(BusinessScopeEnums.ALL.getId());
//            }else if(!calUtil.isEquals(bBusiness.getOfflineStatus(),StaticUtils.STATUS_FAIL)
//                    && calUtil.isEquals(bBusiness.getStatus(),StaticUtils.STATUS_NO)){
//                //线下未驳回 线上是未申请的状态
//                RestResponse restResponse = checkBusinessApplyNoReject(business);
//                if (!restResponse.isStatus()) {
//                    return restResponse;
//                }
//                business.setStatus(StaticUtils.STATUS_APPLY);
//                business.setOnOff(BusinessScopeEnums.ALL.getId());
//            }
//        }
//        if (StringUtils.isNotBlank(business.getUrls())) {
//            JSONArray jsonArray = new JSONArray();
//            String[] urls = business.getUrls().split(",");
//            for (String url : urls) {
//                JSONObject obj = new JSONObject();
//                obj.put("url",url);
//                jsonArray.add(obj);
//            }
//            business.setCoverUrl(jsonArray.toString());
//        }
//        //检查认证情况
//        QueryWrapper<CCustomerAuthen> wrapper = new QueryWrapper<CCustomerAuthen>();
//        wrapper.eq("cid", cid).eq("status", StaticUtils.STATUS_SUCCESS);
//        CCustomerAuthen authen = customerAuthenService.getOne(wrapper);
//        if (authen == null) {
//            return GetRest.getFail("该用户未认证，请认证后再申请！");
//        }
//        business.setFromType(FromTypeEnums.SELF_SETTLED.getId());
//        return businessService.editBusinessForApi(business);
//    }

    /**
     * 查询商家申请情况
     *
     * @param token 获取cid
     * @return com.function.common.RestResponse
     * @author leehao
     */
    @GetMapping(value = CustomerMapping.QUERY_APPLY_STATUS)
    public RestResponse queryApplyStatus(String token) {
        Integer cid = loginTokenService.validLoginCid(token);
        CCustomer customer = icCustomerService.getById(cid);
        if (customer == null) {
            return GetRest.getFail("该用户不存在");
        }
        QueryWrapper<BBusiness> wrapper = new QueryWrapper<>();
        wrapper.eq("cid", cid);
        BBusiness bBusiness = businessService.getOne(wrapper);
        Map<String, Object> map = new HashMap<String, Object>(16);

        /**
         * flag
         * 0 从未申请
         * 1 申请中【给出线上或线下】
         * 2 申请被驳回【给出线上或线下】
         * 3 单个申请通过【给出线上或线下】
         * 4 均通过
         *
         * 0 => 可以申请线上和线下，资料不回显
         * 1 => 点击查看提示信息“平台将在...”
         * 2 => 提示驳回原因，可以重新申请被驳回的部分，资料需回显
         * 3 => 提示后台地址信息，可以继续申请另一部分，需要给到已申请部分的onOff
         * 4 => 不提醒，无按钮
         */
        CalcuUtils calUtil = CalcuUtils.getInstance();
        UrlVo urlVo = null;
        if (bBusiness != null) {
            Properties properties = Config.properties;
            Integer status = bBusiness.getStatus();
            Integer offlineStatus = bBusiness.getOfflineStatus();
            if (calUtil.isEquals(status, StaticUtils.STATUS_APPLY)
                    || calUtil.isEquals(offlineStatus, StaticUtils.STATUS_APPLY)) {
                return GetRest.getSuccess("", null, "1");
            } else if (calUtil.isEquals(status, StaticUtils.STATUS_FAIL)
                    && calUtil.isEquals(offlineStatus, StaticUtils.STATUS_NO)) {
                //线上被驳回 线下未申请
                map.put("id", bBusiness.getId());
                map.put("onOff", BusinessScopeEnums.ONLINE.getId());
                map.put("success", StaticUtils.STATUS_YES);
                map.put("rejRemark", bBusiness.getRejRemark());
                return GetRest.getSuccess("", map, "2");
            } else if (calUtil.isEquals(offlineStatus, StaticUtils.STATUS_FAIL)
                    && calUtil.isEquals(status, StaticUtils.STATUS_NO)) {
                //线下被驳回 线上未申请
                map.put("id", bBusiness.getId());
                map.put("onOff", BusinessScopeEnums.OFFLINE.getId());
                map.put("success", StaticUtils.STATUS_YES);
                map.put("rejRemark", bBusiness.getRejRemark());
                return GetRest.getSuccess("", map, "2");
            } else if (calUtil.isEquals(status, StaticUtils.STATUS_SUCCESS)
                    && calUtil.isEquals(offlineStatus, StaticUtils.STATUS_FAIL)) {
                //线上已通过 线下被驳回
                map.put("id", bBusiness.getId());
                map.put("onOff", BusinessScopeEnums.OFFLINE.getId());
                map.put("success", StaticUtils.STATUS_NO);
                map.put("rejRemark", bBusiness.getRejRemark());
                return GetRest.getSuccess("", map, "2");
            } else if (calUtil.isEquals(offlineStatus, StaticUtils.STATUS_SUCCESS)
                    && calUtil.isEquals(status, StaticUtils.STATUS_FAIL)) {
                //线下已通过 线上被驳回
                map.put("id", bBusiness.getId());
                map.put("onOff", BusinessScopeEnums.ONLINE.getId());
                map.put("success", StaticUtils.STATUS_NO);
                map.put("rejRemark", bBusiness.getRejRemark());
                return GetRest.getSuccess("", map, "2");
            } else if (calUtil.isEquals(status, StaticUtils.STATUS_SUCCESS)
                    && (calUtil.isEquals(offlineStatus, StaticUtils.STATUS_NO)
                    || calUtil.isEquals(offlineStatus, StaticUtils.STATUS_APPLY))
                    && !calUtil.isEquals(offlineStatus, StaticUtils.STATUS_FAIL)) {
                //如果是 线上审核通过 线下未申请或者申请中且不是被驳回
                urlVo = new UrlVo(properties.getBusinessDomain(), customer.getPhone());
                map.put("id", bBusiness.getId());
                map.put("onOff", BusinessScopeEnums.OFFLINE.getId());
                map.put("message", urlVo);
                return GetRest.getSuccess("", map, "3");
            } else if (calUtil.isEquals(offlineStatus, StaticUtils.STATUS_SUCCESS)
                    && (calUtil.isEquals(status, StaticUtils.STATUS_NO)
                    || calUtil.isEquals(status, StaticUtils.STATUS_APPLY))
                    && !calUtil.isEquals(status, StaticUtils.STATUS_FAIL)) {
                //如果是 线上未申请或者申请中且不是被驳回 线下审核通过
                urlVo = new UrlVo(properties.getBusinessDomain(), customer.getPhone());
                map.put("id", bBusiness.getId());
                map.put("onOff", BusinessScopeEnums.ONLINE.getId());
                map.put("message", urlVo);
                return GetRest.getSuccess("", map, "3");
            } else if (calUtil.isEquals(status, StaticUtils.STATUS_SUCCESS)
                    && calUtil.isEquals(offlineStatus, StaticUtils.STATUS_SUCCESS)) {
                urlVo = new UrlVo(properties.getBusinessDomain(), customer.getPhone());
                map.put("message", urlVo);
                return GetRest.getSuccess("", map, "4");
            }

            //如果有商家数据且status和offlineStatus都是0 则是个人商家所创建
            if (calUtil.isEquals(status, StaticUtils.STATUS_NO) &&
                    calUtil.isEquals(offlineStatus, StaticUtils.STATUS_NO)) {
                return GetRest.getSuccess("", null, "0");
            }
        } else {
            return GetRest.getSuccess("", null, "0");
        }
        return GetRest.getFail("状态异常");
    }

    /**
     * 查看申请入驻的资料
     *
     * @param token token获取cid
     * @return com.function.common.RestResponse
     * @author leehao
     */
    @RequestMapping(value = MappingUtils.SHOW_APPLY_BUSINESS_DETAIL)
    public RestResponse showApplyBusinessDetail(String token) {
        Integer cid = loginTokenService.validLoginCid(token);
        QueryWrapper<BBusiness> wrapper = new QueryWrapper<>();
        wrapper.eq("cid", cid);
        BBusiness bBusiness = businessService.getOne(wrapper);
        if (bBusiness == null) {
            return GetRest.getFail("该用户申请资料不存在");
        }
        bBusiness.setCid(null);
        bBusiness.setPayWord(null);
        bBusiness.setScale(null);
        if (StringUtils.isNotBlank(bBusiness.getCoverUrl())) {
            JSONArray jsonArray = JSON.parseArray(bBusiness.getCoverUrl());
            StringBuffer coverUrl = new StringBuffer();
            for (int i = 0; i < jsonArray.size(); i++) {
                String str = "";
                JSONObject jsonObject = (JSONObject) JSONObject.toJSON(jsonArray.get(i));
                str = (String) jsonObject.get("url");
                coverUrl.append(str);
                if (i < jsonArray.size() - 1) {
                    coverUrl.append(",");
                }
            }
            bBusiness.setCoverUrl(coverUrl.toString());
        }
        //地址回填
        String addrName = iAddressService.getAddrName(bBusiness.getProId(),
                bBusiness.getCityId(), bBusiness.getAreaId());
        bBusiness.setAddressName(addrName);
        //行业名称回填
        bBusiness.setIndustryName(industryService.getById(bBusiness.getIndustryId()).getName());
        return GetRest.getSuccess("", bBusiness);
    }

    /**
     * 查询所有线上行业
     *
     * @return
     * @author xiaoky
     */
    @RequestMapping(value = MappingUtils.QUERY_ONLINE_INDUSTRY)
    public RestResponse queryBusinessIndustry() {
        QueryWrapper<Industry> wrapper = new QueryWrapper<Industry>();
        wrapper.eq("on_off", BusinessScopeEnums.ONLINE.getId()).eq("status", StaticUtils.STATUS_YES);
        wrapper.orderByDesc("sort");
        List<Industry> industryList = industryService.list(wrapper);
        return GetRest.getSuccess("", industryList);
    }

    /**
     * 没有申请过其它的范围 第一次被驳回
     *
     * @param business      提交的入驻资料
     * @param originalScope 原来的申请类型
     * @return com.function.common.RestResponse
     * @author leehao
     */
    private RestResponse checkBusinessApplyFirst(BBusiness business, Integer originalScope) {
        CalcuUtils calUtil = CalcuUtils.getInstance();
        RpxUtils rpxUtil = RpxUtils.getInstance();
        if (calUtil.isEquals(originalScope, BusinessScopeEnums.ONLINE.getId())) {
            if (StringUtils.isBlank(business.getLogo())) {
                return GetRest.getFail("请上传店铺头像");
            }
            if (StringUtils.isBlank(business.getNickNameOn())) {
                return GetRest.getFail("请输入线上店铺名");
            }
//            if (StringUtils.isBlank(business.getCompanyName())) {
//                return GetRest.getFail("请输入企业名称");
//            }
            if (StringUtils.isBlank(business.getRealName())) {
                return GetRest.getFail("请输入法人姓名");
            }
        } else if (calUtil.isEquals(originalScope, BusinessScopeEnums.OFFLINE.getId())) {
            if (StringUtils.isBlank(business.getHeadUrl())) {
                return GetRest.getFail("请上传店铺头像");
            }
            if (StringUtils.isBlank(business.getNickName())) {
                return GetRest.getFail("请输入线下店铺名");
            }
            if (StringUtils.isBlank(business.getLinkPhone())) {
                return GetRest.getFail("请输入线下联系电话");
            }
            if (!StringUtils.equals(rpxUtil.validPhone(business.getLinkPhone()), "")) {
                return GetRest.getFail(rpxUtil.validPhone(business.getLinkPhone()));
            }
            if (StringUtils.isBlank(business.getUrls())) {
                return GetRest.getFail("请上传店铺门头照");
            }
        }
//        if (StringUtils.isBlank(business.getCompanyName())) {
//            return GetRest.getFail("请输入企业名称");
//        }
        if (StringUtils.isBlank(business.getRealName())) {
            return GetRest.getFail("请输入法人姓名");
        }
        if (StringUtils.isBlank(business.getCardFileFront())) {
            return GetRest.getFail("请上传法人证件照（相片面）");
        }
        if (StringUtils.isBlank(business.getCardFileBack())) {
            return GetRest.getFail("请上传法人证件照（国徽面）");
        }
        if (StringUtils.isBlank(business.getBusLicense())) {
            return GetRest.getFail("请上传营业执照");
        }
        if (StringUtils.isBlank(business.getLicenseCode())) {
            return GetRest.getFail("请填写营业执照号");
        }
        if (business.getLicenseCode().length() < 15) {
            return GetRest.getFail("请输入正确的营业执照号（15位）");
        }
        if (StringUtils.isBlank(business.getPhone())) {
            return GetRest.getFail("请输入联系电话");
        }
        if (!StringUtils.equals(rpxUtil.validPhone(business.getPhone()), "")) {
            return GetRest.getFail(rpxUtil.validPhone(business.getPhone()));
        }
        if (business.getIndustryId() == null) {
            return GetRest.getFail("请选择所属行业");
        }
        if (business.getProId() == null
                || business.getCityId() == null
                || business.getAreaId() == null) {
            return GetRest.getFail("请选择所在地区");
        }
        if (StringUtils.isBlank(business.getAddressDetail())) {
            return GetRest.getFail("请输入详细地址");
        }
        return GetRest.getSuccess("校验成功");
    }

    /**
     * 有申请过其它的范围 不是第一次被驳回
     *
     * @param business      提交的入驻资料
     * @param originalScope 原来的申请类型
     * @return com.function.common.RestResponse
     * @author leehao
     */
    private RestResponse checkBusinessApplySecond(BBusiness business, Integer originalScope) {
        CalcuUtils calUtil = CalcuUtils.getInstance();
        if (calUtil.isEquals(originalScope, BusinessScopeEnums.ONLINE.getId())) {
            if (StringUtils.isBlank(business.getLogo())) {
                return GetRest.getFail("请上传店铺头像");
            }
            if (StringUtils.isBlank(business.getNickNameOn())) {
                return GetRest.getFail("请输入线上店铺名");
            }
        } else if (calUtil.isEquals(originalScope, BusinessScopeEnums.OFFLINE.getId())) {
            if (StringUtils.isBlank(business.getHeadUrl())) {
                return GetRest.getFail("请上传店铺头像");
            }
            if (StringUtils.isBlank(business.getNickName())) {
                return GetRest.getFail("请输入线下店铺名");
            }
            if (StringUtils.isBlank(business.getLinkPhone())) {
                return GetRest.getFail("请输入线下联系电话");
            }
            RpxUtils rpxUtil = RpxUtils.getInstance();
            if (!StringUtils.equals(rpxUtil.validPhone(business.getLinkPhone()), "")) {
                return GetRest.getFail(rpxUtil.validPhone(business.getLinkPhone()));
            }
            if (StringUtils.isBlank(business.getUrls())) {
                return GetRest.getFail("请上传店铺门头照");
            }
        }
        return GetRest.getSuccess("校验成功");
    }

    /**
     * 没被驳回 继续申请其他范围
     *
     * @param business 申请入驻资料
     * @return com.function.common.RestResponse
     * @author leehao
     */
    private RestResponse checkBusinessApplyNoReject(BBusiness business) {
        CalcuUtils calUtil = CalcuUtils.getInstance();
        if (calUtil.isEquals(business.getOnOff(), BusinessScopeEnums.ONLINE.getId())) {
            //
            if (StringUtils.isBlank(business.getLogo())) {
                return GetRest.getFail("请上传店铺头像");
            }
            if (StringUtils.isBlank(business.getNickNameOn())) {
                return GetRest.getFail("请输入线上店铺名");
            }
        } else if (calUtil.isEquals(business.getOnOff(), BusinessScopeEnums.OFFLINE.getId())) {
            //
            if (StringUtils.isBlank(business.getHeadUrl())) {
                return GetRest.getFail("请上传店铺头像");
            }
            if (StringUtils.isBlank(business.getNickName())) {
                return GetRest.getFail("请输入店铺名称");
            }
            if (StringUtils.isBlank(business.getLinkPhone())) {
                return GetRest.getFail("请输入线下联系电话");
            }
            RpxUtils rpxUtil = RpxUtils.getInstance();
            if (!StringUtils.equals(rpxUtil.validPhone(business.getLinkPhone()), "")) {
                return GetRest.getFail(rpxUtil.validPhone(business.getLinkPhone()));
            }
            if (StringUtils.isBlank(business.getUrls())) {
                return GetRest.getFail("请上传店铺门头照");
            }
        }
        return GetRest.getSuccess("校验成功");
    }
}
